package com.shanzhu.tourism.controller;

import com.shanzhu.tourism.domain.Product;
import com.shanzhu.tourism.domain.ProductOrder;
import com.shanzhu.tourism.domain.Result;
import com.shanzhu.tourism.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: cc
 * @Date: 2025/03/28/15:07
 **/
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @GetMapping("/list")
    public Result list(Product product) {
        return productService.getProductList(product);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Long productId) {
        Product product = productService.getProductById(productId);
        return Result.success(product);
    }

    @PostMapping("/order/create")
    public Result createOrder(@RequestBody ProductOrder order) {
        return productService.createOrder(order);
    }

    @GetMapping("/order/list")
    public Result orderList(Long userId) {
        List<ProductOrder> orders = productService.getOrderList(userId);
        return Result.success(orders);
    }
}